package com.rhit.rosehack.engine;

/*
 * This is Gui for our Rose-Hack. Its responsibilities will be to display the Map, as well as capture Key Events  
 */

import java.awt.Color;
import java.awt.Font;
import java.awt.event.KeyEvent;

import javax.swing.JFrame;

import squidpony.squidgrid.gui.awt.event.SGKeyListener;
import squidpony.squidgrid.gui.swing.SwingPane;


public class GUI extends JFrame{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private SwingPane myGUI;
	private SGKeyListener myListener;
	private String s1,s2,s3;
	
	/*
	 * Creates the Gui Class
	 */
	public GUI()
	{	
		myGUI = new SwingPane(128, 62, new Font("Ariel", Font.PLAIN, 16));
		this.add(myGUI);
		this.setVisible(true);
		this.setResizable(false);
		this.setSize(1920, 1000);
		this.setFocusable(false);
//		myFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		myGUI.setFocusable(true);
		this.myListener = new SGKeyListener(true, SGKeyListener.CaptureType.DOWN);
		
		myGUI.addKeyListener(myListener);
		
		myGUI.refresh();
		myGUI.requestFocus();
		this.s1 = new String("                                                                                                                                ");
		this.s2 = new String("                                                                                                                                ");
		this.s3 = new String("                                                                                                                                ");
	}	
	
	//Returns the next KeyEvent, blocks if there is nothing in the queue, waiting for a key press.
	public KeyEvent getKeyEvent()
	{
		this.myGUI.requestFocus();
		return this.myListener.next();
	}
	
	//Places a single character.
	public void placeCharacter(int x, int y, char a, Color c)
	{
		this.myGUI.placeCharacter(x, y, a, c);
		this.myGUI.refresh();
	}
	
	public void placeMap(char[][] map)
	{
		for(int y = 0; y < map.length; y++)
			for(int x = 0; x < map[0].length; x ++)
		this.myGUI.placeCharacter(x, y, map[y][x]);
		myGUI.refresh();
	}
	
	public void placeHUD(int atk, int def, int mag, int HP, int MP, String name, int currentFloor)
	{
		this.myGUI.placeHorizontalString(0, 57, "--------------------------------------------------------------------------------------------------------------------------------",Color.CYAN,Color.black);
		this.myGUI.placeHorizontalString(0, 58, "Player Name: "+name,Color.CYAN,Color.black);
		this.myGUI.placeHorizontalString(0, 59, "HP:"+ HP +" MP:"+ MP +" ATK:" + atk + " DEF:" + def +" MAG:"+mag+ " FLOOR:" + currentFloor,Color.CYAN,Color.black);
		this.myGUI.refresh();
		
	}
	
	public void placeMessage(String message)
	{
		this.s1 = new String(this.s2);
		this.s2 = new String(this.s3);
		this.s3 = new String(message).concat("                                                                                                                                                                                                                                                                ");
		
		this.myGUI.placeHorizontalString(0, 54, this.s1.substring(0, 127),Color.white, Color.black);
		this.myGUI.placeHorizontalString(0, 55, this.s2.substring(0, 127),Color.white, Color.black);
		this.myGUI.placeHorizontalString(0, 56, this.s3.substring(0, 127),Color.white, Color.black);
	}
}